<?php
if (!defined('ROOT')) exit('SYTbHelper');
//签到相关
class index_model extends base {
	private $tblist;
	static private $_instance=NULL;
	static public function getInstance () {
		if (!self::$_instance) self::$_instance=new self;
		return self::$_instance;
	}
	//初始化函数
	public function __construct () {
		parent::init();
		$_ENV['_now']='index';
		$this->tblist=$this->db('get','tblist');
	}
	//body
	public function onbody () {
		include(TPL.'index_body.html');
	}
	//检查登录信息
	public function onlogin () {
		$tips='';
		if (isset($_POST['submit'])) {
			$pwd=md5(getgpc('pwd','P'));
			setcookie('sythpwd',$pwd,time()+3600*24);
			if (PWD===$pwd) {
				echo '<script>window.location.href="index.php?m=index&a=body";</script>';
				exit;
			} else {
				$tips='<div class="alert alert-danger">密码错误</div>';
				include(TPL.'index_login.html');
			}
		} else {
			include(TPL.'index_login.html');
		}
	}
	//退出
	public function onloginout () {
		setcookie('sythpwd','a',time()-3600);
		echo '<script>window.location.href="index.php?m=index&a=body";</script>';
		exit;
	}
	//检查新版本
	public function onchecknew () {
	$ver=jd(curl_get('http://lab.sylingd.com/api/version/tbhelper.json'));
	if ($ver['version']==VERSION) echo json_encode(array('new'=>0));
	else echo json_encode(array_merge($ver,array('new'=>1)));
	}
}
?>